package com.lhx.wechat.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.util.Properties;

/**
 * Properties工具类
 */
public final class PropertiesUtils {
	
	private static Logger log = LoggerFactory.getLogger(PropertiesUtils.class);
	
	private static Properties keyProperties = new Properties();
	
	private static Properties secretProperties = new Properties();

	static {
		try {
			InputStream is = Thread.currentThread().getContextClassLoader()
					.getResourceAsStream("properties/wechat-key.properties");
			keyProperties.load(is);
			is.close();
			InputStream is2 = Thread.currentThread().getContextClassLoader()
					.getResourceAsStream("properties/wechat-secret.properties");
			secretProperties.load(is2);

			is2.close();
		} catch (Exception e) {
			log.error(e.getMessage());
		}
	}

	/**
	 * 根据 appId 获取 微信支付的商户key
	 * 
	 * @param appId
	 * @return
	 */
	public static String getKeyByAppId(String appId) {
		return keyProperties.getProperty(appId);
	}

	/**
	 * 根据 appId 获取 微信公众平台的appSecret
	 * 
	 * @param appId
	 * @return
	 */
	public static String getSecretByAppId(String appId) {
		return secretProperties.getProperty(appId);
	}
}
